<template>
  <div class="box">
    <!-- 头部 -->
    <div class="headBox">
      <van-icon name="arrow-left" class="icon_bo" @click="fanhui" />
      <h5 class="chattext">评价服务</h5>
    </div>
    <!-- 主体部分 -->
    <div class="main">
      <!-- 文字评价 -->
      <div class="textbox">
        <span class="gangshu">|</span>
        <span class="pingtext">文字评价 (送H币)</span>
        <van-field v-model="commentText" placeholder="请输入你对医生的评价" label-align="top" />
      </div>
      <!-- 星级评价 -->
      <div class="starbox">
        <span class="gangshu">|</span>
        <span class="pingtext">星级评价</span>
        <p>
          <span style="float: left" class="docterzhuanye">医生专业度:</span>
          <van-rate v-model="avalue" style="margin-top: 10px; padding-left: 10px" />
        </p>
        <p>
          <span style="float: left" class="docterzhuanyea">服务满意度:</span>
          <van-rate v-model="bvalue" style="margin-top: 20px; padding-left: 10px" />
        </p>
      </div>
      <!-- 底部 -->
      <div class="footerbox">
        <van-button type="default" class="buttona">返回</van-button>
        <van-button type="primary" class="buttona" @click="submitComment">完成</van-button>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import router from '@/router'
import { ref } from 'vue'
import { showNotify } from 'vant'
import { usecurrentStore } from '../../stores/Consultation'

const avalue = ref(3) // 星级评价的默认值\
const bvalue = ref(2)
const commentText = ref('') // 文字评价的内容
const store:any = usecurrentStore()
import { useRoute } from 'vue-router'
import Toast from 'vant/lib/toast/Toast'

const route = useRoute()

const { recordId, doctorId } = route.query

const fanhui = () => {
  router.push('/history')
}
const submitComment = async () => {
  try {
    const userId = store.userId
    const sessionId = store.sessionId
    const evaluate = commentText.value
    const majorDegree = avalue.value
    const satisfactionDegree = bvalue.value

    await store.handPingdata(
      userId,
      sessionId,
      Number(recordId),
      Number(doctorId),
      evaluate,
      majorDegree,
      satisfactionDegree
    )
    if (store.pingListResults && store.pingListResults.status === '0000') {
      showNotify({ type: 'success', message: '评价成功' })
      router.push({
        path: '/evaluation_results',
        query: { recordId }
      })
    } else {
      showNotify({ type: 'danger', message: '亲，不能重复评论' })
    }
  } catch (error) {
    console.error('提交评论失败', error)
  }
}
</script>
<style scoped lang="scss">
.box {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
// 头部
.headBox {
  width: 100%;
  height: 40px;
  background-color: white;
  border-bottom: 1px solid #ccc;
  .icon_bo {
    float: left;
    line-height: 40px;
    font-size: 20px;
  }
  .chattext {
    text-align: center;
    line-height: 40px;
    font-size: 15px;
  }
}
.main {
  flex: 1;
  background-color: #ece9e9;
  .textbox {
    width: 100%;
    height: 30%;
    background-color: #fff;
    margin-top: 8px;
    .gangshu {
      font-weight: 900;
      font-size: 25px;
      color: rgb(48, 135, 234);
      margin-left: 0.4rem;
    }
    .pingtext {
      font-size: 14px;
      padding-left: 10px;
    }
  }
  .starbox {
    width: 100%;
    height: 25%;
    background-color: #fff;
    margin-top: 5px;
    .gangshu {
      font-weight: 900;
      font-size: 25px;
      color: rgb(48, 135, 234);
      margin-left: 0.4rem;
    }
    .pingtext {
      font-size: 14px;
      padding-left: 10px;
    }
    .docterzhuanye {
      font-size: 14px;
      margin-left: 30px;
      margin-top: 10px;
    }
    .docterzhuanyea {
      font-size: 14px;
      margin-left: 30px;
      margin-top: 20px;
    }
  }
  .footerbox {
    height: 43%;
    background-color: #fff;
    margin-top: 2px;
    .buttona {
      margin-left: 1.5rem;
      margin-top: 4rem;
      width: 100px;
    }
  }
}
</style>
